<template>
  <div class="container-xl bg-white">
    <CreatedQuestion :close="() => { router.push({ name: '题库' }) }" :getstart="getquestion" :ID="ID"
      :asynccreateorupdatequestion="asynccreateorupdatequestion" :istype="false" :isrange="false" :teams="teams"
      :userid="$store.getters.getuser?.ID">
    </CreatedQuestion>
  </div>
</template>
<script setup lang="ts">
import {
  computed,
} from "vue";
import CreatedQuestion from '../../components/createdquestion/index.vue';

import { useRoute, useRouter } from "vue-router";
import { useStore } from 'vuex';
import {
  asynccreateorupdatequestion,
  asyncgetquestion,
} from "../../../api/index";
import { Storekey } from '../../../interface';

const teams = computed(() => {
  return store.state.team?.rows.filter(e => {
    if (!e.allowquestion) return true
    if (e.userid === store.state.user?.ID) return true
    if (e.teamuser?.find(z => z.userid === store.state.user?.ID && z.isAdmin)) return true
    return false
  }) || []
})

const router = useRouter();

const store = useStore(Storekey)
const route = useRoute()
const ID = computed<number | undefined>(() => {
  return route.query.ID as unknown as number
})
// XXX 临时代码
async function getquestion(data: { ID: number }) {
  const ID = data.ID
  const q = await asyncgetquestion({ ID })
  if (q.userid === store.state.user?.ID) {
    return q
  }
  throw '没有权限'
}

</script>

<style scoped>
.container-xl {
  margin-top: 40px;
}
</style>

<style>
.row10 textarea {
  height: 80px;
}
</style>